﻿using System;
using System.Collections.Generic;
using BlobNet.Base.Collections;
using BlobNet.Base.Enums;
using BlobNet.TestsCommon.UnitTests.Dummy;
using BlobNet.TestsCommon.Utils;
using NUnit.Framework;

namespace BlobNet.Base.Tests.UnitTests.CustomCollectionsTests
{
    [TestFixture]
    [Category("Unit Tests")]
    public class BlobListTests
    {
        //TODO: WRAPPER UNIT TESTS with explicit stubs


        [Test]
        public void Can_AddBlobPartDettached_Without_BlobDomain()
        {
            var target = new BlobList<DummyBlobPart>();

            target.Add(new DummyBlobPart() {Property1 = "p"});

            //assert
            Assert.IsTrue(target.Count == 1);

            Assert.AreEqual(target[0].Property1, "p");
        }

        [Test]
        public void Can_AddObject_Without_BlobDomain()
        {
            var target = new BlobList<DummyBlobPart>();

            target.Add(new DummyBlobPart() { Property1 = "p" });

            //assert
            Assert.IsTrue(target.Count == 1);

            Assert.AreEqual(target[0].Property1, "p");
        }

        [Test]
        public void Can_Add_Range()
        {
            BlobDomain blobDomain = TestsHelper.GetDummyBlobDomain();

            var expected = new List<DummyBlobPart>();

            expected.Add(new DummyBlobPart("p1"));
            expected.Add(new DummyBlobPart("p2"));

            var target = new BlobList<DummyBlobPart>(blobDomain, new List<DummyBlobPart>());
            target.AddRange(expected);

            Assert.IsTrue(target.Count == 2);
            Assert.AreEqual(target[0].Property1, expected[0].Property1);
            Assert.AreEqual(target[1].Property1, expected[1].Property1);
        }

        [Test]
        public void Can_BeOf_OnlyAcceptedTypes()
        {
            Assert.DoesNotThrow(() => new BlobList<int>());
            Assert.DoesNotThrow(() => new BlobList<DummyBlobPart>());

            Assert.Throws(typeof (NotSupportedException), () => new BlobList<object[]>());
            Assert.Throws(typeof (NotSupportedException), () => new BlobList<object>());
        }

        [Test]
        public void Can_CreateList_Without_BlobDomain()
        {
            var target = new BlobList<DummyBlobPart>();

            //assert
            Assert.IsTrue(target.StatusStorage == StatusStorageType.Memory);
            Assert.IsTrue(target.Count == 0);
        }

        [Test]
        [Ignore]
        public void Can_Get_Range()
        {
            Assert.Inconclusive();
        }

      
        [Test]
        public void Can_StoreInDb_List_Without_BlobDomain()
        {
            var target = new BlobList<DummyBlobPart>();

            //assert
            Assert.Throws(typeof (InvalidOperationException), () => target.StatusStorage = StatusStorageType.Persistent);
        }

        [Test]
        public void Cant_AddBlobPartAttached_Without_BlobDomain()
        {
            var target = new BlobList<DummyBlobPart>();

            var dummyBlobPart = new DummyBlobPart(TestsHelper.GetDummyBlobDomain()) {Property1 = "p"};

            //assert
            Assert.Throws(typeof (InvalidOperationException), () => target.Add(dummyBlobPart));
        }

    }
}